classdef TestDotsDrawableLines < dotsTestCase
    
    properties
        n;
        x;
        y;
        lines;
        drawManager;
        drawGroup;
    end
    
    methods
        function self = TestDotsDrawableLines(name)
            self = self@dotsTestCase(name);
        end
        
        function setUp(self)
            self.setUp@dotsTestCase;

            dotsTheScreen.reset;
            dotsTheDrawablesManager.reset;
            self.drawManager = dotsTheDrawablesManager.theObject;
            
            self.drawGroup = 'test lines';
            self.lines = self.drawManager.newObject('dotsDrawableLines');
            self.drawManager.addObjectToGroup(self.lines, self.drawGroup);
            self.drawManager.activeGroup = self.drawGroup;
            
            self.drawManager.openScreenWindow;
            
            self.n = 10;
            rect = self.lines.windowRect;
            hx = 0.4*rect(3)/self.lines.pixelsPerDegree;
            hy = 0.4*rect(4)/self.lines.pixelsPerDegree;
            
            self.x = hx*ones(1, 2*self.n);
            self.y = hy*ones(1, 2*self.n);
            self.x(1:2:end) = linspace(-hx, hx, self.n);
            self.y(1:2:end) = linspace(hy, -hy, self.n);
        end
        
        function tearDown(self)
            self.drawManager.closeScreenWindow;
            dotsTheDrawablesManager.reset;
            dotsTheScreen.reset;
            self.tearDown@dotsTestCase;
        end
        
        function testDrawDifferentThings(self)
        
        	% draw no lines
            self.drawManager.mayDrawNextFrame;
            
            % don't draw invisivle lise
            self.lines.isVisible = false;
            self.drawManager.mayDrawNextFrame;
            
            % draw one line
            self.lines.x = self.x(1:2);
            self.lines.y = self.y(1:2);
            self.lines.isVisible = true;

            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
        
            % draw colorful fat line
            self.lines.x = self.x(1:2);
            self.lines.y = self.y(1:2);
            self.lines.width = 10;
            self.lines.color = [255 0 0; 0 0 255]';
            
            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            % draw many lines
            self.lines.x = self.x;
            self.lines.y = self.y;
            self.lines.color = [255 0 0];

            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            % draw many widths
            self.lines.x = self.x;
            self.lines.y = self.y;
            self.lines.width = linspace(1,10,self.n);

            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
            
            % draw many colors
            self.lines.x = self.x;
            self.lines.y = self.y;

            R = linspace(0, 255, self.n);
            G = linspace(128, 255, self.n);
            B = linspace(255, 0, self.n);
            A = linspace(64, 196, self.n);
            c(1:4, 2:2:self.n*2) = cat(1, R, G, B, A);
            c(1:4, 1:2:self.n*2) = cat(1, R, G, B, A);
            self.lines.color = c;

            self.drawManager.mayDrawNextFrame;
            dotsTestCase.waitForLookSee;
        end
    end
end